package com.somg.disruptor_study.demo01.longevent;

import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import com.somg.disruptor_study.demo01.stringevent.StringEvent;

public class LongEventHandler implements EventHandler<LongEvent>{
	
	private Disruptor disruptor;
	
	
	

	public Disruptor getDisruptor() {
		return disruptor;
	}




	public void setDisruptor(Disruptor disruptor) {
		this.disruptor = disruptor;
	}




	public void onEvent(LongEvent event, long arg1, boolean arg2)
			throws Exception {
		
		System.out.println("long handler Event"+ event.getValue());
		long num = event.getValue();
			RingBuffer<StringEvent> ringbuf = disruptor.getRingBuffer();
			long sequence = ringbuf.next();
		try{
			StringEvent sevent = ringbuf.get(sequence);
			sevent.setValue("long num send :"+num);
		}finally{
			ringbuf.publish(sequence);
		}
		
		
	}

}
